package awt.container;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author xiaoqi
 * @data 2021/05/15 12:15
 */
public class DialogDemo {
    public static void main(String[] args) {
        Frame frame = new Frame();
        //1.创建两个dialog对话框
        Dialog d1 = new Dialog(frame, "模式对话框", true);
        Dialog d2 = new Dialog(frame, "非模式对话框", false);
        //2.设置大小，位置
        d1.setBounds(30, 40, 300 ,500);
        d2.setBounds(30, 40, 300 ,500);
        Box cbox = Box.createHorizontalBox();
        cbox.add(new Button("确定"));
        cbox.add(Box.createHorizontalStrut(10));
        cbox.add(new Button("取消"));
        d2.add(cbox, BorderLayout.CENTER);
        d1.add(cbox, BorderLayout.CENTER);
        //3.设置两个按钮
        //4.给这两个按钮添加行为
        //5.将按钮添加打frame中
        Button b1 = new Button("按钮一");
        Button b2 = new Button("按钮二");
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d1.setVisible(true);
            }
        });
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d2.setVisible(true);
            }
        });
        frame.add(b1, BorderLayout.NORTH);
        frame.add(b2);
        frame.pack();
        frame.setVisible(true);
    }
}
